package loginlog

import (
	"context"
	"devops-super/api/syslog/v1"
	"devops-super/internal/service"
)

func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.LoginGetPageLstReq) (res *v1.LoginGetPageLstRes, err error) {
	res = &v1.LoginGetPageLstRes{}
	res, err = service.LoginLog().GetPageLst(ctx, req)
	return
}

func (*ControllerV1) GetOne(ctx context.Context, req *v1.LoginGetOneReq) (res *v1.LoginGetOneRes, err error) {
	res = &v1.LoginGetOneRes{}
	data, err := service.LoginLog().GetOne(ctx, req.InfoId)
	if err != nil {
		return nil, err
	}
	res.Info = data
	return res, nil
}

func (*ControllerV1) Add(ctx context.Context, req *v1.LoginAddReq) (res *v1.LoginAddRes, err error) {
	res = &v1.LoginAddRes{}
	infoId, err := service.LoginLog().Add(ctx, req.LoginLog)
	if err != nil {
		return nil, err
	}
	res.InfoId = infoId
	return res, nil
}

func (*ControllerV1) Del(ctx context.Context, req *v1.LoginDelReq) (res *v1.LoginDelRes, err error) {
	res = &v1.LoginDelRes{}
	rows, err := service.LoginLog().Del(ctx, req.InfoId)
	if err != nil {
		return nil, err
	}
	res.Rows = rows
	return res, nil
}

func (*ControllerV1) BatchDel(ctx context.Context, req *v1.LoginBatchDelReq) (res *v1.LoginBatchDelRes, err error) {
	res = &v1.LoginBatchDelRes{}
	rows, err := service.LoginLog().BatchDel(ctx, req.InfoIds)
	if err != nil {
		return nil, err
	}
	res.Rows = rows
	return res, nil
}
